package com.ruoyi.controller.production;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.production.MesProductionReturnDetail;
import com.ruoyi.service.production.IMesProductionReturnDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 生产退料单明细Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/production/returnDetail")
public class MesProductionReturnDetailController extends BaseController {
    @Autowired
    private IMesProductionReturnDetailService IMesProductionReturnDetailService;

    /**
     * 查询生产退料单明细列表
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesProductionReturnDetail mesProductionReturnDetail) {
        startPage();
        List<MesProductionReturnDetail> list = IMesProductionReturnDetailService.selectMesProductionReturnDetailList(mesProductionReturnDetail);
        return getDataTable(list);
    }

    /**
     * 导出生产退料单明细列表
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:export')")
    @Log(title = "生产退料单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesProductionReturnDetail mesProductionReturnDetail) {
        List<MesProductionReturnDetail> list = IMesProductionReturnDetailService.selectMesProductionReturnDetailList(mesProductionReturnDetail);
        ExcelUtil<MesProductionReturnDetail> util = new ExcelUtil<MesProductionReturnDetail>(MesProductionReturnDetail.class);
        util.exportExcel(response, list, "生产退料单明细数据");
    }

    /**
     * 获取生产退料单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId) {
        return success(IMesProductionReturnDetailService.selectMesProductionReturnDetailByDetailId(detailId));
    }

    /**
     * 新增生产退料单明细
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:add')")
    @Log(title = "生产退料单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesProductionReturnDetail mesProductionReturnDetail) {
        return toAjax(IMesProductionReturnDetailService.insertMesProductionReturnDetail(mesProductionReturnDetail));
    }

    /**
     * 修改生产退料单明细
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:edit')")
    @Log(title = "生产退料单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesProductionReturnDetail mesProductionReturnDetail) {
        return toAjax(IMesProductionReturnDetailService.updateMesProductionReturnDetail(mesProductionReturnDetail));
    }

    /**
     * 删除生产退料单明细
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:remove')")
    @Log(title = "生产退料单明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds) {
        return toAjax(IMesProductionReturnDetailService.deleteMesProductionReturnDetailByDetailIds(detailIds));
    }

    /**
     * 根据退料单ID查询明细列表
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:list')")
    @GetMapping("/listByReturnId/{returnId}")
    public AjaxResult listByReturnId(@PathVariable Long returnId) {
        List<MesProductionReturnDetail> list = IMesProductionReturnDetailService.selectDetailListByReturnId(returnId);
        return success(list);
    }

    /**
     * 批量新增生产退料单明细
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:add')")
    @Log(title = "批量新增生产退料单明细", businessType = BusinessType.INSERT)
    @PostMapping("/batchAdd")
    public AjaxResult batchAdd(@RequestBody List<MesProductionReturnDetail> detailList) {
        return toAjax(IMesProductionReturnDetailService.batchInsertMesProductionReturnDetail(detailList));
    }

    /**
     * 根据退料单ID删除明细
     */
    @PreAuthorize("@ss.hasPermi('production:returnDetail:remove')")
    @Log(title = "删除生产退料单明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteByReturnId/{returnId}")
    public AjaxResult deleteByReturnId(@PathVariable Long returnId) {
        return toAjax(IMesProductionReturnDetailService.deleteMesProductionReturnDetailByReturnId(returnId));
    }
}